﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AyaWo.Commen;

namespace Qbqqban
{
    public class BlogColumn
    {
        public string Columnid { get; set; }
        public string name { get; set; }
        public string info { get; set; }
        public string CreatedBy { get; set; }
        public DateTime CreatedDate { get; set; }
        public string ModifiedBy { get; set; }
        public DateTime ModifiedDate { get; set; }
        public int Deleteflag { get; set; }
        public string Rowversion { get; set; }
    }

    public class BlogColumnBll
    {
        public static void AddType(string name)
        {
            BlogColumn bc = new Qbqqban.BlogColumn();
            bc.Columnid = CommonHelper.CreateNo();
            bc.name = name;
            bc.CreatedBy = "1";
            bc.CreatedDate = DateTime.Now;
            bc.Deleteflag = 0;
            string sqlStr = "INSERT INTO blogcolumn(Columnid,name,CreatedBy,CreatedDate,Deleteflag) values(@Columnid,@name,@CreatedBy,@CreatedDate,@Deleteflag)";
            BaseService.Db.ExecuteBySql(new StringBuilder(sqlStr), bc);
        }

        public static bool canAdd(string name)
        {
            if (name.IsNullOrWhiteSpace())
                return false;
            try
            {
                var q = BaseService.Db.GetDataTableBySqL(new StringBuilder("select Columnid FROM blogcolumn t WHERE t.`name`=@name"), new { name = name });
                if (q == null || q.Rows.Count == 0)
                    return true;
                else return false;
            }
            catch (Exception ex)
            {
                return false;
            }
        }


        public static string GetID(string name)
        {
            if (name.IsNullOrWhiteSpace())
                return null;
            try
            {
                var q = BaseService.Db.GetDataListBySqL<BlogColumn>(new StringBuilder("select Columnid FROM blogcolumn t WHERE t.`name`=@name"), new { name = name });
                if (q == null || q.Count() == 0)
                    return null;
                else return q.Select(x=>x.Columnid).FirstOrDefault();
            }
            catch (Exception ex)
            {
                return null;
            }
        }
    }
}
